﻿using System.Xml.Linq;
using NJabber.Stream.Elements;
using NUnit.Framework;

namespace NJabber.Stream.Elements
{
    [TestFixture]
    public class StanzaTest : StanzaTestBase
    {
        public StanzaTest() : base("stanza", "", "")
        {
        }

        [Test]
        public void Equals_TypePropertiesEquals_ReturnsTrue()
        {
            Stanza stanza1 = CreateStanza("get");
            Stanza stanza2 = CreateStanza("get");

            Assert.That(stanza1.Equals(stanza2), Is.True);
        }

        [Test]
        public void Equals_TypePropertiesNotEquals_ReturnsFalse()
        {
            Stanza stanza1 = CreateStanza("get");
            Stanza stanza2 = CreateStanza("set");

            Assert.That(stanza1.Equals(stanza2), Is.False);
        }

        [Test]
        public void Write_NotEmptyTypeProperty_WritesCorrectXml()
        {
            string stanzaType = "some-type";
            Stanza stanza = CreateStanza(stanzaType);
            XElement expectedElement = CreateStanzaXElement(Name, stanzaType);

            VerifyWriteOutput(expectedElement, stanza);
        }

        [Test]
        public void Equals_DifferentType_ReturnsFalse()
        {
            Stanza stanza1 = CreateStanza("result");
            Stanza stanza2 = CreateStanza("americana");

            Assert.That(stanza1.Equals(stanza2), Is.False);
        }

        [Test]
        public void Equals_SameType_ReturnsTrue()
        {
            Stanza stanza1 = CreateStanza("mary");
            Stanza stanza2 = CreateStanza("mary");

            Assert.That(stanza1.Equals(stanza2), Is.True);
        }

        private Stanza CreateStanza(string type)
        {
            Stanza stanza = CreateStreamElementMock<Stanza>(Name);
            stanza.Type = type;
            return stanza;
        }
    }
}
